import { Middleware, IMiddleware, Inject } from '@midwayjs/core';
import { NextFunction, Context } from '@midwayjs/koa';
import WechatService from '../service/wechat.service';

@Middleware()
export class WechatMiddleware implements IMiddleware<Context, NextFunction> {
    @Inject()
    wechatService: WechatService;
    resolve() {
        return async (ctx: Context, next: NextFunction) => {
            // 控制器前执行的逻辑
            this.wechatService.wechat({})(ctx.request, ctx.response, next);
            // 这里可以拿到下一个中间件或者控制器的返回值
            const result = await next();
            // 返回给上一个中间件的结果
            return result;
        };
    }

    static getName(): string {
        return 'wechat';
    }
}
